#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e6+100;
typedef long long LL;
LL a[maxn],dp[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;cin>>n;
  for(LL i=1;i<=n;i++) cin>>a[i];
  for(LL i=1;i<=n;i++){
    dp[i]=max(dp[i-1]+a[i],a[i]);
  }
  LL ans=-1e18;
  for(LL i=1;i<=n;i++){
    ans=max(ans,dp[i]);
  }
  cout<<ans<<endl;
return 0;
}
